<?php
namespace Home\Controller;

class CloudController extends BaseController {

    public function aws(){
        $cates = D('CloudCate')->where(['type'=>'aws'])->select();
        $this->assign('cates', $cates);

        $clouds = D('Cloud')->where(['type'=>'aws'])->select();
        $list = [];
        foreach ($clouds as $v){
            $v['desc'] = stringToText($v['content'], 30);
            foreach ($cates as $v2){
                if($v['cate_id'] == $v2['id']){
                    $list[$v['cate_id']][] = $v;
                }
            }
        }

        $list = array_values($list);
        $this->assign('list', $list);

        $this->display();
    }

    public function alibabacloud(){
        $this->display();
    }

    public function azure(){
        $cates = D('CloudCate')->where(['type'=>'azure'])->select();
        $this->assign('cates', $cates);

        $clouds = D('Cloud')->where(['type'=>'azure'])->select();
        $list = [];
        foreach ($clouds as $v){
            $v['desc'] = stringToText($v['content'], 30);
            foreach ($cates as $v2){
                if($v['cate_id'] == $v2['id']){
                    $list[$v['cate_id']][] = $v;
                }
            }
        }

        $list = array_values($list);
        $this->assign('list', $list);

        $this->display();
    }

    public function cloudflare(){
        $this->display();
    }

    public function googlecloud(){
        $cates = D('CloudCate')->where(['type'=>'google'])->select();
        $this->assign('cates', $cates);

        $clouds = D('Cloud')->where(['type'=>'google'])->select();
        $list = [];
        foreach ($clouds as $v){
            $v['desc'] = stringToText($v['content'], 30);
            foreach ($cates as $v2){
                if($v['cate_id'] == $v2['id']){
                    $list[$v['cate_id']][] = $v;
                }
            }
        }

        $list = array_values($list);
        $this->assign('list', $list);

        $this->display();
    }

    public function huaweicloud(){
        $cates = D('CloudCate')->where(['type'=>'huawei'])->select();
        $this->assign('cates', $cates);

        $clouds = D('Cloud')->where(['type'=>'huawei'])->select();
        $list = [];
        foreach ($clouds as $v){
            $v['desc'] = stringToText($v['content'], 30);
            foreach ($cates as $v2){
                if($v['cate_id'] == $v2['id']){
                    $list[$v['cate_id']][] = $v;
                }
            }
        }

        $list = array_values($list);
        $this->assign('list', $list);

        $this->display();
    }

    public function tencentcloud(){
        $cates = D('CloudCate')->where(['type'=>'tencent'])->select();
        $this->assign('cates', $cates);

        $clouds = D('Cloud')->where(['type'=>'tencent'])->select();
        $list = [];
        foreach ($clouds as $v){
            $v['desc'] = stringToText($v['content'], 30);
            foreach ($cates as $v2){
                if($v['cate_id'] == $v2['id']){
                    $list[$v['cate_id']][] = $v;
                }
            }
        }

        $list = array_values($list);
        $this->assign('list', $list);

        $this->display();
    }

}